using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JSON;

public class JSONEquipSuit{
	#region 单例
	private static JSONEquipSuit instance;
	public static JSONEquipSuit getInstance(){
	if (instance == null)
		instance = new JSONEquipSuit ();
		return instance;
	}
	#endregion

	#region 变量
	private JSONNode json;
	private JSONNode JSONData{
		get{
			if(json == null)
				json = JsonRead.Read("JSONEquipSuit");
			return json;
		}
	}
	#endregion
	#region 外部调用
	public void Clear(){
		json = null;
	}
	public JSONNode GetJSON(string key){
		return JSONData [key];
	}
	public JSONNode GetJSON(int index){
		return JSONData [index];
	}
	/// <summary>
	/// 有多少个数据
	/// </summary>
	public int GetCount(){
	return JSONData.Count;
	}

    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListID(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetID(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 套装ID
	/// </summary>
	public int GetID(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["ID"].AsInt;
		return  value;
	}
	/// <summary>
	/// 套装ID :From Index
	/// </summary>
	public int GetID(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetID(index.ToString());
			return  value;
		}
		value = json["ID"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListName(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetName(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 套装名称
	/// </summary>
	public string GetName(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Name"].ToString();
		return  value;
	}
	/// <summary>
	/// 套装名称 :From Index
	/// </summary>
	public string GetName(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetName(index.ToString());
			return  value;
		}
		value = json["Name"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListInfo(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetInfo(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 套装信息
	/// </summary>
	public string GetInfo(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Info"].ToString();
		return  value;
	}
	/// <summary>
	/// 套装信息 :From Index
	/// </summary>
	public string GetInfo(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetInfo(index.ToString());
			return  value;
		}
		value = json["Info"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListHead(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetHead(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 头
	/// </summary>
	public int GetHead(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Head"].AsInt;
		return  value;
	}
	/// <summary>
	/// 头 :From Index
	/// </summary>
	public int GetHead(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetHead(index.ToString());
			return  value;
		}
		value = json["Head"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListWeapon(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetWeapon(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 武器
	/// </summary>
	public int GetWeapon(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Weapon"].AsInt;
		return  value;
	}
	/// <summary>
	/// 武器 :From Index
	/// </summary>
	public int GetWeapon(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetWeapon(index.ToString());
			return  value;
		}
		value = json["Weapon"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListCloth(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetCloth(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 胸甲
	/// </summary>
	public int GetCloth(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Cloth"].AsInt;
		return  value;
	}
	/// <summary>
	/// 胸甲 :From Index
	/// </summary>
	public int GetCloth(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetCloth(index.ToString());
			return  value;
		}
		value = json["Cloth"].AsInt;
		return  value;
	}

	#endregion
}